package com.tencent.sr.iris.basic.mp.restapi.controller.activity;

import com.tencent.sr.iris.activity.interfaces.response.SearchAfterPaginationResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.ActivityStaticResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.FlowActivityInfoResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.LongTermAwardStaticResponse;
import com.tencent.sr.iris.activity.interfaces.response.activity.UserActivityInfoResponse;
import com.tencent.sr.iris.basic.mp.common.exception.SystemCommErrorCode;
import com.tencent.sr.iris.basic.mp.common.util.AssertUtils;
import com.tencent.sr.iris.basic.mp.interfaces.request.*;
import com.tencent.sr.iris.basic.mp.interfaces.response.MpUserTaskRecordResponse;
import com.tencent.sr.iris.basic.mp.service.activity.UserTaskService;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "活动任务", value = "活动任务相关接口")
@RestController
@RequestMapping("/iris/basic/mp/v1/user/task")
public class UserTaskController {

    @Resource
    private UserTaskService userTaskService;

    @PostMapping("page")
    @ApiOperation("会员任务情况分页列表")
    public HttpResult<SearchAfterPaginationResponse<MpUserTaskRecordResponse>> page(
            @Validated @RequestBody PaginationRequest<MpUserTaskRecordRequest> request) {
        SearchAfterPaginationResponse<MpUserTaskRecordResponse> page = userTaskService.page(request);
        return HttpResult.succ(page);
    }


    @PostMapping("/getJuniorTaskRecordList")
    @ApiOperation("获取下级的任务记录")
    public HttpResult<SearchAfterPaginationResponse<MpUserTaskRecordResponse>> getJuniorTaskRecordList(
            @Validated @RequestBody PaginationRequest<MpGetJuniorTaskRecordListRequest> request) {
        SearchAfterPaginationResponse<MpUserTaskRecordResponse> page = userTaskService.getJuniorTaskRecordList(request);
        return HttpResult.succ(page);
    }

    @PostMapping("longTermAward")
    @ApiOperation("长期激励统计")
    public HttpResult<LongTermAwardStaticResponse> longTermAward(
            @Validated @RequestBody MpLongTermAwardStaticRequest request) {
        LongTermAwardStaticResponse staticResponse = userTaskService.longTermAward(request);
        return HttpResult.succ(staticResponse);
    }

    @PostMapping("userActivityInfo")
    @ApiOperation("用户活动信息")
    public HttpResult<UserActivityInfoResponse> userActivityInfo() {
        UserActivityInfoResponse response = userTaskService.userActivityInfo();
        return HttpResult.succ(response);
    }

    @PostMapping("queryFlowActivityInfo")
    @ApiOperation("查询余额流水活动信息")
    public HttpResult<FlowActivityInfoResponse> queryFlowActivityInfo(
            @Validated @RequestBody MpFlowActivityInfoRequest request) {
        boolean notValid = request.getTaskRecordId() == null && request.getTaskId() == null;
        AssertUtils.isFalse(notValid, SystemCommErrorCode.PARAM_ERROR);
        FlowActivityInfoResponse staticResponse = userTaskService.queryFlowActivityInfo(request);
        return HttpResult.succ(staticResponse);
    }

    @PostMapping("/activityStatic")
    @ApiOperation(value = "统计所有活动的奖励金")
    public HttpResult<ActivityStaticResponse> activityStatic(@Validated @RequestBody MpActivityStaticRequest activityStaticRequest) {
        ActivityStaticResponse response = userTaskService.activityStatic(activityStaticRequest);
        return HttpResult.succ(response);
    }
}
